<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑预约信息</title>
</head>
<body>
<div align="center">
    <h1>编辑日志信息</h1>
</div>
<div>
<h3>预约基本信息</h3>
</div>
<form action="/orders/updateOrdersByProId" method="post" id="upForm">
<#--    隐藏的预约编号-->
    <input type="hidden" value="${orders.proId}" name="proId">
<p>
    机构名称：
    <select name="insName">
        <#list allOrderIns as a>
            <option  <#if a.insName==orders.insName>selected</#if> >${a.insName}</option>
        </#list>
    </select>
</p>
<p>
    预约联系人:<input type="text" name="userName" value="${orders.userName}">
</p>
    <div>
        <label>
            我的头像：
            <label><img src="${orders.pic}" id="img"></label>
            <input type="hidden" id="hiddenPic2" value="" name="pic">
        </label>
        <p>
            头像：<input type="file" name="picture" onchange="preview2(this)" id="pic"><span></span>
        </p>
        <button type="button" onclick="uploadPic2()" id="upBtn">点我换头像</button>
        </p>
    </div>
<p>
    预约时间:<input type="date" name="orderDate" value="${orders.orderDate?date}">
</p>
<p>
    预约人手机:<input type="text" name="userPhone" value="${orders.userPhone}">
</p>
<p>
    预约目的:<textarea name="orderAim">${orders.orderAim}</textarea>
</p>
<p>
    预约结果:<textarea name="orderResult">${orders.orderResult}</textarea>
</p>
<p>
    预约状态:
    <select name="orderState">
        <option selected>--请选择--</option>
        <#list allStates as sta>
            <option value="${sta.orderId}" <#if sta.orderId==orders.orderState>selected</#if>>${sta.orderName}</option>

        </#list>
    </select>
</p>
<p>
    操作人:<input type="text" name="serverUser" value="${orders.serverUser}">
</p>
<p>
    是否再次预约:
    <input type="radio" name="1" checked="checked">是
    <input type="radio"  name="1">否
</p>
<p>
    预约提醒:
    <input type="radio" name="2" checked="checked">是
    <input type="radio"  name="2">否
</p>
<button type="button" onclick="onsub()">确定编辑</button>
<button type="button" onclick="location.href='/orders/findAll'">取消</button>
</form>
<script type="text/javascript" src="/jquery.js"></script>
<script type="text/javascript">
    function onsub() {
        var data=$("#upForm").serialize();
        $.ajax({
            url:"/orders/updateOrdersByProId",
            data:data,
            type:"post",
            dataType: "json",
            success:function f(result) {
                <#--        修改成功        -->
                if (result.code==6){
                    alert(result.msg);
                    location.href='/orders/findAll';
                }else {
                    alert("编辑失败！！")
                    location.href='/orders/findAll';
                }
            }
        });
    }

    //    动态回显图片
    function preview2(file) {
        if(file.files && file.files[0]){
            reader=new FileReader();
            reader.onload=function (evt) {
                //在图片的src属性赋值，添加图片流的信息
                $("#img").attr("src",evt.target.result);
            }
            reader.readAsDataURL(file.files[0]);
        }
    }
    //    上传图片
    function uploadPic2() {
        //    创建FormData对象
        var formData=new FormData();
        //    向formData中封装文件上传项
        formData.append("file",$("#pic")[0].files[0]);
        //    发送ajax请求
        $.ajax({
            url:"/upload/pic",
            data:formData,
            type:"post",
            dataType:"json",
            success:function (rs) {
                if(rs.code==100){
                    // $("#img").attr("src",rs.data);
                    alert(rs.data);
                    $("#hiddenPic2").val(rs.data);
                    $("#pic").next().html("头像修改成功!!").css("color","green");
                }
                else {
                    alert("服务器爆炸了!!");
                    $("#pic").next().html("头像修改失败!!!").css("color","red");
                }
            } ,
            erorr:function () {
                alert("服务器爆炸了!!")
            },
            contentType:false,
            processData:false
        });
    }

</script>
</body>
</html>